package com.ruoyi.zhgd.controller;

import java.util.*;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.domain.vo.*;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.bo.NCementDataBo;
import com.ruoyi.zhgd.service.INCementDataService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 水稳拌合站数据
 *
 * @author zyb
 * @date 2023-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/cementData")
public class NCementDataController extends BaseController {

    private final INCementDataService iNCementDataService;

    /**
     * 查询水稳拌合站数据列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NCementDataVo> list(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出水稳拌合站数据列表
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NCementDataBo bo, HttpServletResponse response) {
        List<NCementDataVo> list = iNCementDataService.queryList(bo);
        ExcelUtil.exportExcel(list, "水稳拌合站数据", NCementDataVo.class, response);
    }

    /**
     * 获取水稳拌合站数据详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NCementDataVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNCementDataService.queryById(id));
    }

    /**
     * 新增水稳拌合站数据
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NCementDataBo bo) {
        return toAjax(iNCementDataService.insertByBo(bo));
    }

    /**
     * 修改水稳拌合站数据
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NCementDataBo bo) {
        return toAjax(iNCementDataService.updateByBo(bo));
    }

    /**
     * 删除水稳拌合站数据
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "水稳拌合站数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNCementDataService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
    * 获取最新数据年份
    * @author cj
    * @date 2023/10/8 10:57
    * @return 最新数据年份
    **/
    @SaCheckLogin
    @GetMapping("/getLastYear")
    public R getLastYear(@RequestParam Map<String, Object> params) {
        String data = iNCementDataService.getLastYear(params);
        List list = new ArrayList();
        list.add(data);
        return R.ok(list);
    }

    /**
     * 获取最新数据日期
     * @param params
     * @return
     */
    @SaCheckLogin
    @GetMapping("/getLastDay")
    public R<String> getLastDay(@RequestParam Map<String, Object> params) {
        return R.ok("",iNCementDataService.getLastDay(params));
    }
    /**
     * 获取最新一条数据
     * @param params
     * @return
     */
    @SaCheckLogin
    @GetMapping("/getLastData")
    public R<NCementDataVo> getLastData(@RequestParam Map<String, Object> params) {
        return R.ok(iNCementDataService.getLastData(params));
    }

    /**
    * 生产数据监控
    * @author cj
    * @date 2023/10/8 11:08
    * @return 生产数据监控
    **/
    @SaCheckLogin
    @GetMapping("/page")
    public R page(@RequestParam Map<String, Object> params,
                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                  @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", pageNum);
        paramMap.put("limit", pageSize);
        PageUtils pageUtils = iNCementDataService.queryPage(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }

    /**
     * 生产质量监控
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageQuality")
    public TableDataInfo<NCementDataVo> pageQuality(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageQuality(bo, pageQuery);
    }

    /**
     * 获取质量汇总分析数据分页列表
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageQualityStatistics")
    public TableDataInfo<NCementDataQualityStatisticsVo> pageQualityStatistics(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageQualityStatistics(bo, pageQuery);
    }

    /**
     * 总量校核
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageCheck")
    public TableDataInfo<NCementProduceWeightVo> pageCheck(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageCheck(bo, pageQuery);
    }

    /**
     * 水稳产量统计汇总
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageOutputStatistics")
    public TableDataInfo<NCementOutputSummaryVo> pageOutputStatistics(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageOutputStatistics(bo, pageQuery);
    }

    /**
     * 水稳材料消耗
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageMaterielConsume")
    public TableDataInfo<NCementMaterielConsumeVo> pageMaterielConsume(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageMaterielConsume(bo, pageQuery);
    }

    /**
     * 水稳项目产量统计
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/pageProjectStatistics")
    public TableDataInfo<NCementProjectStatisticsListVo> pageProjectStatistics(NCementDataBo bo, PageQuery pageQuery) {
        return iNCementDataService.pageProjectStatistics(bo, pageQuery);
    }

    /**
     * 历年产量数据
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listForYear")
    public R<List<NCementOutputStatisticsVo>> listForYear(NCementDataBo bo) {
        return R.ok(iNCementDataService.listForYear(bo));
    }

    /**
     * 月产量数据
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listForMonth")
    public R<List<NCementOutputStatisticsVo>> listForMonth(NCementDataBo bo) {
        return R.ok(iNCementDataService.listForMonth(bo));
    }

    /**
     * 日产量数据
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listForDay")
    public R<List<NCementOutputStatisticsVo>> listForDay(NCementDataBo bo) {
        return R.ok(iNCementDataService.listForDay(bo));
    }

    /**
     * 项目产量数据
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listForProject")
    public R<List<NCementOutputStatisticsVo>> listForProject(NCementDataBo bo) {
        return R.ok(iNCementDataService.listForProject(bo));
    }
    /**
     * 配方产量数据
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listForMatch")
    public R<List<NCementOutputStatisticsVo>> listForMatch(NCementDataBo bo) {
        return R.ok(iNCementDataService.listForMatch(bo));
    }

    /**
     * 手动校验
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/handCheck")
    public R handCheck(@Validated(EditGroup.class) @RequestBody NCementDataBo bo) {
        iNCementDataService.handCheck(bo);
        return R.ok();
    }

}
